package com.orange.util;

import java.text.SimpleDateFormat;

import android.content.Context;

import com.orange.lswidget.R;

public class DateTimeFormat {

	private static final String	TIME_24_FMT				= "k:mm";
	private static final String	TIME_12_FMT				= "h:mm aa";
	private static final String	DATE_SHORT_FORMAT		= "MMM dd";
	private static final String	DATE_LONG_FORMAT		= "dd MMM yyyy";

	private boolean				mUse24HrFormat			= false;
	private boolean				mShowToday				= false;
	// private boolean mShowYear = false;
	private boolean				mShowTimeWhenNotToday	= false;

	private Context				mContext;

	public DateTimeFormat(Context context) {
		mContext = context;
	}

	public String format(long time) {
		String result = "";

		// format date
		SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_LONG_FORMAT);
		String currDateStr = dateFormat.format(System.currentTimeMillis());
		String dateStr = dateFormat.format(time);
		boolean isToday = dateStr.equals(currDateStr);
		if (isToday) {
			if (mShowToday) {
				result += (String) mContext.getResources().getText(
						R.string.date_val_today);
			}
		} else {
			result += new SimpleDateFormat(DATE_SHORT_FORMAT).format(time);
		}

		// format time
		if (!isToday && !mShowTimeWhenNotToday) {
			// doesn't show time
		} else {
			if (result.length() > 0) {
				result += " ";
			}

			String format = DateTimeUtils.timeFormat_12_24(mContext);
			if (format != null && format.equalsIgnoreCase("24")) {
				mUse24HrFormat = true;
			} else {
				mUse24HrFormat = false;
			}
			result += new SimpleDateFormat(
					mUse24HrFormat ? TIME_24_FMT : TIME_12_FMT).format(time);
		}

		return result;
	}
}
